package com.zephyr.io;

import org.junit.jupiter.api.Test;

import java.io.*;

public class FileCopy {

    private static final String INPUT_FILE = "d://1.txt";
    private static final String OUTPUT_FILE = "d://2.txt";

    @Test
    public void copy() throws IOException {
        long start = System.currentTimeMillis();
        InputStream inputStream = new FileInputStream(INPUT_FILE);
        OutputStream outputStream = new FileOutputStream(OUTPUT_FILE);
        byte[] bytes = new byte[1024];
        int i;
        while ((i = inputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, i);
        }
        inputStream.close();
        outputStream.close();
        System.out.println("耗时:" + (System.currentTimeMillis() - start) + "ms");
    }

    @Test
    public void createFile() throws FileNotFoundException {
        PrintWriter writer = new PrintWriter(new FileOutputStream(INPUT_FILE));
        for (int i = 0; i < 50000000; i++) {
            if (i % 1000000 == 0) {
                System.out.println(i);
            }
            writer.println("hello world " + i);
        }
        writer.close();
    }

}
